<!DOCTYPE html>
<html>

<head>

    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">


    <title>生态瞬时测试</title>
    <meta name="keywords" content="">
    <meta name="description" content="">

    <link rel="shortcut icon" href="favicon.ico">
    <link href="../css/bootstrap.min.css?v=3.3.6" rel="stylesheet">
    <link href="../css/font-awesome.css?v=4.4.0" rel="stylesheet">
    <link href="../css/plugins/iCheck/custom.css" rel="stylesheet">
    <link href="../css/animate.css" rel="stylesheet">
    <link href="../css/style.css?v=4.1.0" rel="stylesheet">
    <link rel="stylesheet" href="../css/paging.css">

</head>

<body class="gray-bg">
<div class="wrapper wrapper-content animated fadeInRight">

    <div class="row">
        <div class="col-sm-12">
            <div class="ibox float-e-margins">
                <div class="ibox-title">
                    <h5>实验管理</h5>
                </div>
                <div class="ibox-content">
                    <div class="row">
                        <div class="col-sm-5 m-b-xs">
                        </div>
                        <div class="col-sm-4 m-b-xs">
                        </div>
                        <div class="col-sm-3">
                            <a href="add-test.html" class="btn btn-sm btn-primary">添加实验</a>
                        </div>
                    </div>
                    <div class="table-responsive">
                        <table class="table table-bordered table-striped">
                            <thead>
                                <tr>
                                    <th>实验名称</th>
                                    <th>被试人数</th>
                                    <th>开始/结束日期</th>
                                    <th>试卷名称</th>
                                    <th>答题策略</th>
                                    <th>操作</th>
                                </tr>
                            </thead>
                            <tbody id="test-box">
                                <!--表格加载内容显示-->
                            </tbody>
                        </table>
                    </div>
                    <div class="paging">
                        <div id="paging" class="page_div"></div>
                    </div>
                </div>

            </div>

        </div>

    </div>
</div>

<!-- 全局js -->

<script src="../js/jquery.min.js?v=2.1.4"></script>
<script src="../js/bootstrap.min.js?v=3.3.6"></script>
<script src="../js/paging.js"></script>
<script src="../js/dateChange.js"></script>
<script src="../js/global.js"></script>
<!-- iCheck -->
<script src="../js/plugins/iCheck/icheck.min.js"></script>
<script>
    $(document).ready(function () {
        $('.i-checks').iCheck({
            checkboxClass: 'icheckbox_square-green',
            radioClass: 'iradio_square-green',
        });
    });
</script>
<script>
   $(document).ready(function () {
       //获取页面数据
       var token = sessionStorage.getItem("token");
       function initData(_data) {
           var token = sessionStorage.getItem("token");
           var num = _data.current;
           var pageSize = _data.size;
           $.ajax({
               type:"GET",
               url:"http://123.206.18.189:8080/experiments",
               data:_data,
               beforeSend: function(xhr){xhr.setRequestHeader('authToken', token);},
               dataType:'json',
               success: function (res) {
                   var html = '';
                   for(var i=0; i<res.data.length;i++){
                       var startT = dateChange(res.data[i].beginDate);
                       var endT = dateChange(res.data[i].endDate);
                       var strategyBeginTime = hmDateChange(res.data[i].strategyBeginTime);
                       var strategyEndTime = hmDateChange(res.data[i].strategyEndTime);
                       var strategyType = res.data[i].strategyType == "RANDOM"?"随机":(res.data[i].strategyType == "FIXED"?"固定":"");
                       var strategy = `${strategyBeginTime} - ${strategyEndTime}   ${res.data[i].strategyRate==undefined?" ":res.data[i].strategyRate}次   ${strategyType}`;
                       if(res.data[i].strategyRate==undefined){
                           strategy = "";
                       }
                       html += `  <tr alt="${res.data[i].id}">
                                    <td>${res.data[i].name}</td>
                                    <td>${res.data[i].subjectNum==undefined?"":res.data[i].subjectNum}</td>
                                    <td>${startT} / ${endT}</td>
                                    <td>${res.data[i].examinationPaperName==undefined?" ":res.data[i].examinationPaperName}</td>
                                    <td>${strategy} </td>
                                    <td>
                                        <i class="fa fa-edit edit" title="修改" style="margin-right: 20px;"></i>
                                        <i class="fa fa-cubes  tactics" title="答题策略" style="margin-right: 20px;"></i>
                                        <i class="fa fa-file-text examPaper" title="试卷管理" style="margin-right: 20px;"></i>
                                        <i class="fa fa-users experimenters" title="被试管理" style="margin-right: 20px;"></i>
                                        <i class="fa fa-user-secret manager" title="实验人员管理" style="margin-right: 20px;"></i>
                                        <i class="fa fa-bar-chart-o export-data" title="导出数据" style="margin-right: 20px;"></i>
                                        <i class="fa fa-trash-o del" title="删除实验" style="margin-right: 20px;"></i>
                                    </td>
                                </tr>`
                   }
                   $('#test-box').html(html);
                   updatePage(res,_data);
               },
               error:function(XMLHttpRequest, textStatus, errorThrown) {
                   console.log(XMLHttpRequest.status);
                   console.log(XMLHttpRequest.readyState);
                   console.log(textStatus);
               },

           });
       }
       initData({current:1,size:10});
       //分页效果
       function updatePage(res,_data) {
           $("#paging").paging({
               pageNo:_data.current,
               totalPage:Math.ceil(res.meta.pagination.total/res.meta.pagination.size),
               callback: function (num) {
                   _data.current = num;
                   initData(_data)
               }
           })
       }
       //删除实验
       $("#test-box").on("click",".del",function () {
           var $testId = $(this).parent().parent().attr("alt");
           var r = confirm("您是否确定删除该实验？");
           if(r){
               $.ajax({
                   type:"DELETE",
                   url:"http://123.206.18.189:8080/experiments/"+$testId,
                   headers:{
                       authToken:token
                   },
                   success:function () {

                   },
                   complete:function (XMLHttpRequest) {
                       if(XMLHttpRequest.status == 200){
                           alert("实验删除成功！");
                           window.location.reload();
                       }
                   }
               })
           }

       })
       //被试者管理
       $("#test-box").on("click",".experimenters",function () {
           var testId = $(this).parent().parent().attr("alt");
           var testName = $(this).parent().parent().children().eq(0).text();
           sessionStorage.setItem("testName",testName);
           sessionStorage.setItem("testId",testId);
           window.location.href = "add-experimental.html";

       })
       //实验者管理
       $("#test-box").on("click",".manager",function () {
           var testId = $(this).parent().parent().attr("alt");
           var testName = $(this).parent().parent().children().eq(0).text();
           sessionStorage.setItem("testName",testName);
           sessionStorage.setItem("testId",testId);
           window.location.href = "add-manager-list.html";
       })


       //答题策略
       $("#test-box").on("click",".tactics",function () {
           var strategyBox = $(this).parent().prev().text();
           var testId = $(this).parent().parent().attr("alt");
           sessionStorage.setItem("testId",testId);
           if(strategyBox == " "){
               window.location.href = "answer-strategy.html";
           }else {
               window.location.href = "answerStrategyChange.html";
           }
       })
       
       //修改
       $("#test-box").on("click",".edit",function () {
           var testId = $(this).parent().parent().attr("alt");
           sessionStorage.setItem("testId",testId);
           window.location.href = "testChange.html";
       })
       //试卷管理
       $("#test-box").on("click",".examPaper",function () {
           var testName = $(this).parent().parent().children().eq(0).text();
           sessionStorage.setItem("testName",testName);
           var testId = $(this).parent().parent().attr("alt");
           sessionStorage.setItem("testId",testId);
           location.href = 'add-examPaper-item.html';
       })
       //导出数据
       $("#test-box").on("click",".export-data",function () {
           var testId = $(this).parent().parent().attr("alt");
           var url = global.host+"/experiments/"+testId+"/examData?authToken=" + token;
           window.open(url,"_blank");
       })
   })
</script>

</body>

</html>
